import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

const store = new Vuex.Store({
  state: {
    position: '北京',
    userName: ''
  },

  mutations: {
    setPosition (state, val) {
      state.position = val
    },
    setUserName (state, val) {
      state.userName = val
    }
  },

  actions: {
    setPosition ({ commit }, val) {
      // 异步请求数据
      commit('setPosition', val)
    }
  }
})

export default store
